home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / c01oop.zip / CPPWKBK / CPPV1-2.CPP < prev    next >
C/C++ Source or Header  |  1992-08-25  |  561b  |  36 lines

  1. #define HEADER "C++ Problem 1.2 by Rick Conn using Borland C++"
  2.  
  3. #include <stdio.h>
  4.  
  5. struct complex {
  6.   double real_part;
  7.   double imag_part;
  8. public:
  9.   void set(double rp, double ip)
  10.   {
  11.     real_part = rp;
  12.     imag_part = ip;
  13.   }
  14.  
  15.   void add_one_to (void)
  16.   {
  17.     real_part += 1.0;
  18.   }
  19.  
  20.   void print (void)
  21.   {
  22.     printf("(%5.1lfi + %5.1lfj)\n", real_part, imag_part);
  23.   }
  24. };
  25.  
  26. void main(void)
  27. {
  28.   printf("%s\n", HEADER);
  29.  
  30.   complex value;
  31.   value.set (20.0, -30.0);
  32.   value.print();
  33.   value.add_one_to();
  34.   value.print();
  35. }
  36.